import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  UserForm,
  UserInfo,
  UserPageVO,
  UserQuery,
  UserInfoQuery,
} from "./types";

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfoApi(params: UserInfoQuery): AxiosPromise<UserInfo> {
  return request({
    url: "admin/login/info",
    method: "get",
    params: params,
  });
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(
  queryParams: UserQuery
): AxiosPromise<PageResult<UserPageVO[]>> {
  return request({
    url: "admin/user/list",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getUserForm(userId: string): AxiosPromise<UserForm> {
  return request({
    url: `admin/user/one/${userId}`,
    method: "get",
  });
}

/**
 * 添加用户
 *
 * @param data
 */
export function saveUser(data: any) {
  return request({
    url: "admin/user/save",
    method: "post",
    data: data,
  });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: string, password: string) {
  return request({
    url: "/api/v1/users/" + id + "/password",
    method: "patch",
    params: { password: password },
  });
}

/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(ids: string[]) {
  return request({
    url: "admin/user/del",
    method: "post",
    data: ids,
  });
}
